package com.iqiyi.pps.epg.core.dao.carousel;

import com.iqiyi.pps.epg.core.dao.base.BaseDao;
import com.iqiyi.pps.epg.core.dao.base.PropertyFilter;
import com.iqiyi.pps.epg.core.model.carousel.CarouselBase;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by lemuelwang on 2015/6/5.
 */
@Component
public class CarouselBaseDao extends BaseDao<CarouselBase>{
    public List<CarouselBase> find(List<PropertyFilter> filters, int maxSize) {
        Criterion[] criterions = buildCriterionByPropertyFilter(filters);
        Criteria criteria = createCriteria(criterions);
        criteria.setMaxResults(maxSize);
        return criteria.list();
    }

    @Transactional
    public int addErrorCount(long id){
        String hql ="update CarouselBase set errorCount = errorCount + 1 where id = ?";
        int executeNum = createQuery(hql).setLong(0,id).executeUpdate();
        return executeNum;
    }

}
